from selenium.webdriver.common.by import By

class ProductsPages:
    def __init__(self,driver):
        self.driver = driver

    url = "http://192.168.0.102/cmrv0.5.1/v0.5.1/index.php?m=user&a=login"
    input_locator = (By.NAME, 'name')  #输入用户名
    password_locator = (By.NAME, 'password')  #输入密码
    btn_locator = (By.CSS_SELECTOR, 'input[value=登录]')  #点击登录
    #头顶页面定位器
    head_locator = (By.CSS_SELECTOR, 'body > div.navbar.navbar-inverse.navbar-fixed-top > div > div')
    #点击产品定位器
    product_locator = (By.CSS_SELECTOR,
                       'body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul:nth-child(1) > li:nth-child(4) > a')
    #点击添加产品定位器
    add_product_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(2) > div.pull-right > a')
    #产品名称定位器
    procduct_name_locator = (By.CSS_SELECTOR, '#name')
    #开发团队定位器
    development_team_locator = (By.CSS_SELECTOR, '#development_team')
    #保存定位器
    submit_locator = (By.CSS_SELECTOR, 'input[value=保存]')


    def input_username(self,username):
        self.driver.find_element(*self.input_locator).send_keys(username)

    def input_password(self,password):
        self.driver.find_element(*self.password_locator).send_keys(password)

    def click_btn_login(self):
        self.driver.find_element(*self.btn_locator).click()

    def click_head(self):
        self.driver.find_element(*self.head_locator).click()

    def click_product(self):
        self.driver.find_element(*self.product_locator).click()

    def click_add_product(self):
        self.driver.find_element(*self.add_product_locator).click()

    def input_product_name(self,pname):
        self.driver.find_element(*self.procduct_name_locator).send_keys(pname)

    def input_team_name(self,tname):
        self.driver.find_element(*self.development_team_locator).send_keys(tname)

    def click_submit(self):
        self.driver.find_element(*self.submit_locator).click()

    def open(self):
        self.driver.get(self.url)